<?php

namespace App\Api;

use PhalApi\Api;


/**
 * 万国觉醒 验证码帐号密码
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */
class RokYzm extends Api
{

    public function getRules()
    {
        return array(
            "GetAccount"     => array(
                'token' => array('name' => 'token', 'require' => true, 'desc' => 'token'),
            ),
            "GetInfo"     => array(
                'username' => array('name' => 'username', 'require' => true, 'desc' => 'username'),
            ),
        );
    }


    /**
     * username 取打码帐号密码
     * @desc 多条件查询接口
     * @return array data 被查数据
     * @exception 400 非法请求，参数传递错误
     */
    public function GetInfo()
    {
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: *');

        $username = $this->username;
        $userinfo = \PhalApi\DI()->notorm->rok_user
            ->where( array("username" => $username ) )->fetchOne();
        return $userinfo ? $userinfo : "";

    }



    /**
     * 通过帐号token取 打码帐号密码
     * @desc 多条件查询接口
     * @return array data 被查数据
     * @exception 400 非法请求，参数传递错误
     */
    public function GetAccount()
    {
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: *');

        $token = $this->token;


        //读出帐号的信息
        $tokeninfo = \PhalApi\DI()->notorm->rok_account
            ->where( array("token" => $token ) )->fetchOne();

        $username = $tokeninfo['user_id'];

        $userinfo = \PhalApi\DI()->notorm->rok_user
            ->where( array("username" => $username ) )->fetchOne();

        return $userinfo ? $userinfo : "";

    }



}
